from meiduo_admin.pages import Mypage
from meiduo_admin.serializers.user_serializer import *
from rest_framework.generics import ListCreateAPIView
from users.models import User


class UserAPIView(ListCreateAPIView):

    queryset = User.objects.filter(is_staff=True)
    serializer_class = UserDetailSerializer
    pagination_class = Mypage    # 选择自定义的分页器

    # 重写过滤的方法
    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return self.queryset.filter(username__contains=keyword)
        return self.queryset.all()

